/*年轻人，只管向前看，不要管自暴自弃者的话*/

import '../../util/time_util.dart';
import '../api_respository.dart';
import '../base/NWMethod.dart';
import '../dio_manager.dart';
import '../http_url.dart';

///create by itz on 2024/1/9 16:25
///desc :
class FamilyUserData {
  int? id;
  String? createdTime;
  String? updatedTime;
  int? childUid;
  int? parentUid;
  int? senderUid;
  int? receiverUid;
  int? status;
  bool? del;
  String? childRemarkName;
  String? parentRemarkName;
  String? childRemarkAvatar;
  String? parentRemarkAvatar;
  bool? read;
  int? permission;
  String? childName;
  String? parentName;
  String? childAvatar;

  String? agreeTime;
  String? childPhone;

  bool? remoteAssist;
  bool? appUser;
  int? guardDays;
  GpsInfo? gps;

  String headImg = "";

  FamilyUserData(
      {this.id,
      this.createdTime,
      this.updatedTime,
      this.childUid,
      this.parentUid,
      this.senderUid,
      this.receiverUid,
      this.status,
      this.del,
      this.childRemarkName,
      this.parentRemarkName,
      this.childRemarkAvatar,
      this.parentRemarkAvatar,
      this.read,
      this.permission,
      this.childName,
      this.parentName,
      this.childAvatar,
      this.agreeTime,
      this.childPhone,
      this.remoteAssist,
      this.appUser,
      this.guardDays,
      this.gps});

  FamilyUserData.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    createdTime = json['createdTime'];
    updatedTime = json['updatedTime'];
    childUid = json['childUid'];
    parentUid = json['parentUid'];
    senderUid = json['senderUid'];
    receiverUid = json['receiverUid'];
    status = json['status'];
    del = json['del'];
    childRemarkName = json['childRemarkName'];
    parentRemarkName = json['parentRemarkName'];
    childRemarkAvatar = json['childRemarkAvatar'];
    parentRemarkAvatar = json['parentRemarkAvatar'];
    read = json['read'];
    permission = json['permission'];
    childName = json['childName'];
    parentName = json['parentName'];
    childAvatar = json['childAvatar'];
    agreeTime = json['agreeTime'];
    childPhone = json['childPhone'];
    remoteAssist = json['remoteAssist'];
    appUser = json['appUser'];
    guardDays = json['guardDays'];
    gps = json['gps'] != null ? GpsInfo.fromJson(json['gps']) : null;
  }

  String getShowName() {
    if (childRemarkName != null && childRemarkName!.isNotEmpty) {
      return childRemarkName!;
    }
    if (childName != null && childName!.isNotEmpty) {
      return childName!;
    }
    return "";
  }

  void getHeadImg() {
    if (headImg != "") {
      return;
    }
    String url = "${HttpUrl.signedUrl}$childAvatar";
    var header = DioManager.headers();
    header["r_tag"] = "$childAvatar";
    ApiRepository.instance.request<String>(url, header: header, method: NWMethod.GET, success: (it) {
      headImg = it;
    }, error: (e) {
      headImg = "";
    });
  }

  @override
  String toString() {
    return 'FamilyUserData{id: $id, createdTime: $createdTime, updatedTime: $updatedTime, childUid: $childUid, parentUid: $parentUid, senderUid: $senderUid, receiverUid: $receiverUid, status: $status, del: $del, childRemarkName: $childRemarkName, parentRemarkName: $parentRemarkName, childRemarkAvatar: $childRemarkAvatar, parentRemarkAvatar: $parentRemarkAvatar, read: $read, permission: $permission, childName: $childName, parentName: $parentName, childAvatar: $childAvatar, agreeTime: $agreeTime, childPhone: $childPhone, remoteAssist: $remoteAssist, appUser: $appUser, guardDays: $guardDays, gps: $gps}';
  }
}

class GpsInfo {
  String? createdTime;
  String? updatedTime;
  int? uid;
  String? longitude;
  String? latitude;
  String? country;
  String? province;
  String? city;
  String? area;
  String? street;
  String? address;

  GpsInfo(
      {this.createdTime,
      this.updatedTime,
      this.uid,
      this.longitude,
      this.latitude,
      this.country,
      this.province,
      this.city,
      this.area,
      this.street,
      this.address});

  GpsInfo.fromJson(Map<String, dynamic> json) {
    createdTime = json['createdTime'];
    updatedTime = json['updatedTime'];
    uid = json['uid'];
    longitude = json['longitude'];
    latitude = json['latitude'];
    country = json['country'];
    province = json['province'];
    city = json['city'];
    area = json['area'];
    street = json['street'];
    address = json['address'];
  }

  String getUpdatedTime() {
    return TimeUtil.refreshTimeFormat(createdTime);
  }

  @override
  String toString() {
    return 'GpsInfo{createdTime: $createdTime, updatedTime: $updatedTime, uid: $uid, longitude: $longitude, latitude: $latitude, country: $country, province: $province, city: $city, area: $area, street: $street, address: $address}';
  }
}
